home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 10.4 KB | 413 lines | [TEXT/MPS ] |
- // UCalcCell.h
- // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UCALCCELL__
- #define __UCALCCELL__
-
- //
- // INTERNAL INCLUDES FOR CALC
- //
-
- #ifndef __UCALC__
- #include "UCalc.h"
- #endif
-
- #ifndef __CALCUTILITIES__
- #include "CalcUtilities.h"
- #endif
-
-
- class TCell;
- class TCellList;
- class CCalcCellIterator;
- class CSelectedExistingCalcCellIterator;
-
- //--------------------------------------------------------------------------------------------------
- // TCellList:
- //--------------------------------------------------------------------------------------------------
-
- class TCellList : public TList
- {
- MA_DECLARE_CLASS;
-
- public:
- virtual ~TCellList();
- // Destructor
-
- virtual void ICellList();
- // Init the list procedurally
-
- virtual CompareResult Compare(TObject* item1, TObject* item2); // override
- // Compares cells based on row and column number
-
- virtual TCell* GetCell(RowNumber r, ColumnNumber c);
- // Returns the cell whose row,column is r,c
- }; // TCellList
-
-
- //--------------------------------------------------------------------------------------------------
- // TCell: TCell describes one element of the spreadsheet grid.
- //--------------------------------------------------------------------------------------------------
-
- class TCell : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- Boolean fDeleted; // Whether the cell has been deleted
- TCalcDocument* fCalcDocument; // The document I belong to
-
- RowNumber fRow; // Which row I'm in
- ColumnNumber fColumn; // Which column I'm in
-
- KindOfCell fKind; // What kind of cell: text, value, empty, error
- EvalResult fError; // Error code from my latest evaluation
- Boolean fEvaluating; // flag for preventing self reference loops
- ValueType fValue; // My value represented as a number
- ValueString fValueString; // My value represented as a CString, for display
- CStr255 fFormula; // My contents as typed in by the user
- Boolean fMarked; // !!!RCR For change notification
-
- TCell();
- // Constructor
-
- virtual void ICell(TCalcDocument* owningDocument,
- RowNumber r,
- ColumnNumber c);
- // Initialize the cell's fields
-
- virtual TObject* Clone(); // override
- /* Create a new cell which is a copy of this cell, except for dependents and
- references */
-
- virtual void CopyContents(TCell* sourceCell);
- // Copy contents of sourceCell
-
- virtual ~TCell(); // override
- // Free my lists and then free me
-
- virtual void EvaluateFormula(Boolean updateDependencies,
- Boolean& cellChanged);
- /* Calculate my value by evaluating fFormula. If updateDependencies is true, add me
- to the list of dependents of any cells referenced in my formula. Return true in
- cellChanged if my fValue or fKind has changed */
-
- virtual void GetAsString(CStr255& theString);
- // Return my formula CString
-
- virtual void GetValueAsString(CStr255& theString);
- // Return a CString representation of my value
-
- virtual void invalidate();
- // Cause a cell to be marked invalid (in need of re-drawing).
-
- virtual CPoint GetCoordinates();
- // Returns a CPoint describing the Cell's location on the GridView
-
- virtual Boolean IsEmpty();
- // Return true if I have no formula or value
-
- virtual void SetDeleteState(Boolean deleted);
- // Mark a cell as deleted or not deleted
-
- virtual void SetToString(const CStr255& theString);
- // Set my formula to theString and recalculate my value if necessary
-
- virtual void Recalculate(Boolean forceAutomatic,
- Boolean updateDependencies);
- // Re-evaluate my formula CString. Notify dependent cells of the change
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);// Override
- /* Update this cell in response to a change in a cell referenced in this
- cell's formula */
-
- virtual ArrayIndex GetNoOfDependentCells();
- // Returns the size of the dependent list
-
- virtual ArrayIndex GetNoOfReferencedCells();
- // Returns the size of the dependent list
-
- virtual TDependencySpace* GetDependencySpace(); // Override
- // Overridden to return the document's dependency space
-
- virtual void AddDependentCell(TCell* aCell);
- // Add aCell to this cell's list of dependents
-
- virtual void RemoveDependentCell(TCell* aCell);
- // Remove aCell from this cell's list of dependents
-
- virtual void ValueToString();
- // Fill fValueString with the CString representation of my value
-
- virtual short GetDiskSize(Boolean infoRecordOnly);
-
- virtual void ReadFromDisk(TFile* aFile);
-
- virtual void WriteToDisk(TFile* aFile);
-
- virtual void WriteCellCoordinateToDisk(TFile* aFile);
-
- virtual void ReadFromScrap(Handle theScrap, long& scrapOffset);
-
- virtual void WriteToScrap(Handle theScrap, long& scrapOffset);
-
- }; // TCell
-
-
- //--------------------------------------------------------------------------------------------------
- // TCellEditCommand: TCellEditCommand is a command object created to handle the cCopy,
- // cCut, and cClear menu commands.
- //--------------------------------------------------------------------------------------------------
-
- class TCellEditCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TCalcDocument* fCalcDocument;
- RgnHandle fSelection; // cells selected when command was created
-
- virtual void ICellEditCommand(TCalcDocument* itsDocument,
- CommandNumber itsCommand);
- /* Initialize the command object. Save the current cell selection for later
- Undo/Redo */
-
- virtual ~TCellEditCommand(); // override
- // Clean up our stuff
-
- virtual void DoIt(); // override
- // Edit the currently selected cells
-
- virtual void UndoIt(); // override
- // Undo the edit of the cells
-
- virtual void RedoIt(); // override
- // Redo the edit of the cells
-
- virtual void Commit(); // override
- // Commit the edit of the cells
-
- virtual void CopySelection();
- // Copy the currently selected cell(s) into the clipboard
-
- virtual void DeleteSelection();
- // Delete the currently selected cell(s)
-
- virtual void RestoreSelection();
- // Restore the deleted cells
-
- virtual void ReSelect();
- // Change the selection back to what it was when this command was created
-
- }; // TCellEditCommand
-
-
- //--------------------------------------------------------------------------------------------------
- // TCellPasteCommand: A command object created to handle the cPaste menu command.
- //--------------------------------------------------------------------------------------------------
-
- class TCellPasteCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TCalcDocument* fClipDocument;
- TCalcDocument* fCalcDocument;
- RgnHandle fSelection; // cells selected when command was created
- TCellList* fReplacedCells; // the cells we pasted over
-
- virtual void ICellPasteCommand(TCalcDocument* itsDocument);
- // Initialize the command object
-
- virtual ~TCellPasteCommand(); // override
- // We don' need this command no more
-
- virtual void DoIt(); // override
- // Paste to the currently selected cells. Save this selection for Undo/Redo.
-
- virtual void UndoIt(); // override
- // Undo the paste of the cells
-
- virtual void RedoIt(); // override
- // Redo the paste of the cells
-
- virtual void UpdateViews();
- // Redisplay the affected cells
- }; // TCellPasteCommand
-
-
- class CCalcCellIterator : public CObjectIterator
- {
- public:
- CCalcCellIterator(TCalcDocument* theCalcDocument);
-
- CCalcCellIterator(TCellList* theCellList);
-
- virtual ~CCalcCellIterator();
-
- virtual TCell* CurrentCell();
- // returns the current Cell
-
- virtual TCell* FirstCell();
- // return the first Cell in the iteration
-
- virtual TCell* NextCell();
- // advances the iteration and then returns the Cell
- };
-
-
- class CSelectedExistingCalcCellIterator : public CCalcCellIterator
- {
- public:
- CSelectedExistingCalcCellIterator(TCalcDocument* theCalcDocument);
-
- virtual ~CSelectedExistingCalcCellIterator();
-
- virtual void Reset();
-
- protected:
- RgnHandle fSelectedRegion;
-
- virtual Boolean IsCellSelected(TCell* theCell);
-
- virtual void Advance();
- };
-
-
- class CExistingCalcCellIterator : public CCalcCellIterator
- {
- public:
- CExistingCalcCellIterator(TCalcDocument* theCalcDocument);
-
- virtual ~CExistingCalcCellIterator();
-
- virtual void Reset();
-
- protected:
- TCalcDocument* fCalcDocument;
-
- virtual Boolean CellExists();
-
- virtual void Advance();
- };
-
-
- class CReferencedCellIterator : public CNotifierIterator
- {
- public:
- CReferencedCellIterator(TCell* theCell);
-
- virtual ~CReferencedCellIterator();
-
- virtual void Reset();
-
- virtual TCell* FirstCell();
-
- virtual TCell* CurrentCell();
-
- virtual TCell* NextCell();
-
- protected:
- virtual Boolean NotifierIsCell();
-
- virtual void Advance();
- };
-
-
- class CDependentCellIterator : public CDependentIterator
- {
- public:
- CDependentCellIterator(TCell* theCell);
-
- virtual ~CDependentCellIterator();
-
- virtual void Reset();
-
- virtual TCell* FirstCell();
-
- virtual TCell* CurrentCell();
-
- virtual TCell* NextCell();
-
- protected:
- virtual Boolean DependentIsCell();
-
- virtual void Advance();
- };
-
-
- class CParseSubscribedText
- {
- public:
- CParseSubscribedText(TDesignator* aDesignator,
- TStream* aStream,
- long length,
- CRect subBounds, // bounds of the subscriber
- CRect pubBounds); // bounds of the publisher
-
- virtual CStr255 ParseSubscribedText(Handle textHdl, GridCell aGridCell);
-
- private:
- CRect subBounds; // bounds of the subscriber
- CRect pubBounds; // bounds of the publisher
- Handle theText;
- TDesignator* theDesignator;
- TStream* theStream;
- long theLength;
- GridCell normalizedCell;
- unsigned char* p;
- long offset;
- long where;
- char aChar;
- long maxLength;
-
- virtual void ScanTo(char ch);
-
- virtual short NumTabs();
- };
-
-
- class CCellParser
- { // takes the text of a cell and evaluates its contents
- public:
- CCellParser(TCell* theCell);
-
- void EvaluateFormula(KindOfCell& theKind,
- EvalResult& theError,
- ValueType& theValue,
- CStr255& theFormula,
- Boolean doUpdateDependencies);
-
- protected:
- TCell* fCell;
- TCalcDocument* fCalcDocument;
- ValueString fValueString;
- CStr255 fFormula;
- short formulaLength;
- short formulaIndex;
- char theChar;
- ValueType theValue;
- Boolean updateDependencies;
-
- void GetNextChar();
-
- EvalResult DoInteger(short& theInteger);
-
- EvalResult DoNumber(ValueType& theValue);
-
- EvalResult DoCellReference(ValueType& theValue);
-
- EvalResult Term(ValueType& theValue);
-
- EvalResult Factor(ValueType& theValue);
-
- EvalResult Expression(ValueType& theValue);
- };
-
-
- #endif
-
-